﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace visualizadordicom.Aux_Forms
{
    public partial class saveresults : Form
    {
        /// <summary>
        /// Initializes the form.
        /// </summary>
        public saveresults()
        {
            InitializeComponent();
        }

        string[] text;
        string file;


        /// <summary>
        /// Gets the informations about the homogeneity test and save it in the proper file
        /// </summary>
        /// <param name="file">
        /// It's the file string path.
        /// </param>
        /// <param name="snrroi">
        /// It's the snr calculated using just the roi informations.
        /// </param>
        /// <param name="snr">
        /// It's the snr calculated using the entire area information.
        /// </param>
        /// <param name="mpvroi">
        /// It's the mpv calculated using just the roi informations.
        /// </param>
        /// <param name="mpv">
        /// It's the mpv  calculated using the entire area information.
        /// </param>
        /// <param name="stdroi">
        /// It's the std calculated using just the roi informations.
        /// </param>
        /// <param name="std">
        /// It's the std  calculated using the entire area information.
        /// </param>
        public saveresults(string file, double snrroi, double snr, double mpvroi, double mpv, double stdroi, double std) 
        {
            InitializeComponent();

            this.file = file;
            text = File.ReadAllLines(this.file);

            textBox1.Text = (Math.Round(snrroi, 2)).ToString();
            textBox2.Text = (Math.Round(snr, 2)).ToString();
            textBox3.Text = (Math.Round(mpvroi, 2)).ToString();
            textBox4.Text = (Math.Round(mpv, 2)).ToString();
            textBox5.Text = (Math.Round(stdroi, 2)).ToString();
            textBox6.Text = (Math.Round(std, 2)).ToString();
            comboBox1.SelectedIndex = 0;

        }


        /// <summary>
        /// Closes the form.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {      
            this.Close();
        }


        /// <summary>
        /// Saves the information into the file.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {

            string[] text2 = new string[text.Length + 7];
            int i = 0;
            foreach(String s in text)
            {
                text2[i] = s;
                i++;
            }


            text2[text.Length + 0] = label1.Text.ToString() + " " + comboBox1.SelectedItem.ToString();
            text2[text.Length + 1] = label2.Text.ToString() + " " + textBox1.Text.ToString();
            text2[text.Length + 2] = label3.Text.ToString() + " " + textBox2.Text.ToString();
            text2[text.Length + 3] = label4.Text.ToString() + " " + textBox3.Text.ToString();
            text2[text.Length + 4] = label5.Text.ToString() + " " + textBox4.Text.ToString();
            text2[text.Length + 5] = label6.Text.ToString() + " " + textBox5.Text.ToString();
            text2[text.Length + 6] = label7.Text.ToString() + " " + textBox6.Text.ToString();

            File.WriteAllLines(file, text2);
            this.Close();
        }
    }
}
